#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#include"StringPool.h"
#include"variable.h"
#include"boost/regex.hpp"
#include"DependencyReader.h"
#include"CONLLReader.h"
#include"MSTReader.h"
using namespace std;
using namespace boost;

DependencyReader::DependencyReader(){
	labeled = false;
	hasEnd = false;
	inputReader = NULL;
}

DependencyReader::~DependencyReader(){}
DependencyReader* DependencyReader::createDependencyReader(string &format, bool discourseMode, bool labeled, bool hasEnd){
	if(format == "MST"){
		return new MSTReader(labeled, hasEnd);
	}
	else if(format == "CONLL"){
		return new CONLLReader(discourseMode, labeled, hasEnd);
	}
	else{
		cout<<"!!!!!!!  Not a supported format: "<<format<<endl;
		cout<<"********* Assuming CONLL format. **********"<<endl;
		return new CONLLReader(discourseMode, labeled, hasEnd);
	}
}

void DependencyReader::finishReading(){
	fclose(inputReader);
}

string* DependencyReader::normalize(string* s){
	regex expression("[0-9]+|[0-9]+\\.[0-9]+|[0-9]+[0-9,]+");
	cmatch what;
	string tmp;
	if(regex_match(s->c_str(), what, expression)){
		tmp = string("<num>");
		return pool->get(tmp);
	}
	else{
		tmp = string(*s);
		return pool->get(tmp);
	}
}

bool DependencyReader::isLabeled(){
	return labeled;
}

void DependencyReader::startReading(const char* file){
	//labeled = fileContainsLabels(file);

	inputReader = fopen(file, "r");
}

bool DependencyReader::fileContainsLabels(const char *filename){
	return true;
}

DependencyInstance* DependencyReader::getNext(){
	return NULL;
}
